﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 药品信息管理
{
    public partial class YP_RZPZ : Form
    {
        public YP_RZPZ()
        {
            InitializeComponent();
        }

        db db1 = new db();

        private void YP_RZPZ_Load(object sender, EventArgs e)
        {

            getSqlConnection myconnection = new 药品信息管理.getSqlConnection();
            SqlConnection conn = myconnection.GetCon();
            SqlCommand mycomm = new SqlCommand("select mc from YK_ZDGYS", conn);
            SqlDataReader myread = mycomm.ExecuteReader();
            while (myread.Read())
            {
                this.comboBoxEx1.Items.Add((string)myread[0]);

            }
            conn.Close();


            SqlConnection conn2 = new SqlConnection(SQL.conStr);
            DataTable dt = new DataTable();
            string str = @"SELECT convert(datetime,RQ-2) 制单日期,   GYS.MC  供应商,  PZH 凭证号,  FPZS 发票张数,  RKDS  入库单张数,  JJJE 购进金额, LJJE 零售金额, CZRY 制单人
                           FROM YK_RZPZ PZ 
                           LEFT JOIN YK_ZDGYS GYS ON PZ.GYSBM = GYS.BM ";
            SqlDataAdapter da = new SqlDataAdapter(str, conn2);
            da.Fill(dt);
            dataGridViewX1.DataSource = dt;

        }

        private void buttonItem1_Click(object sender, EventArgs e)
        {

            string gys_combx="";
            string time1 = dateTimePicker1.Value.ToString("yyyy.MM.dd"), time2 = dateTimePicker2.Value.ToString("yyyy.MM.dd");
            if (comboBoxEx1.SelectedText != "") { gys_combx = " and GYS.MC='" + comboBoxEx1.SelectedText + "' "; }
            SqlConnection conn = new SqlConnection(SQL.conStr);
            DataTable dt = new DataTable();

            string str = @"SELECT PZID,convert(datetime,RQ-2) 制单日期,   GYS.MC  供应商,  PZH 凭证号,  FPZS 发票张数,  RKDS  入库单张数,  JJJE 购进金额, LJJE 零售金额, CZRY 制单人
                           FROM YK_RZPZ PZ 
                           LEFT JOIN YK_ZDGYS GYS ON PZ.GYSBM = GYS.BM 
                           WHERE  PZ.RQ >= " + db1.datetoint(time1) + " AND PZ.RQ <= " + db1.datetoint(time2) + gys_combx;

            SqlDataAdapter da = new SqlDataAdapter(str, conn);
            da.Fill(dt);
            dataGridViewX1.DataSource = dt;
            dataGridViewX1.Columns["PZID"].Visible = false;
        }

        private void buttonItem2_Click(object sender, EventArgs e)
        {
            YP_RZPZ_MX pz = new YP_RZPZ_MX();
            pz.ShowDialog();
        }

        private void dataGridViewX1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            YP_RZPZ_MX pz = new YP_RZPZ_MX();
            pz.pzid = dataGridViewX1.Rows[e.RowIndex].Cells[0].Value.ToString();
            pz.ShowDialog();
        }
    }
}